// stores/userStore.js

// 定义全局的用户存储
const userStore = {
  User: {
    // 初始状态
    schoolId: -1,
    gradeId: -1,
    classId: -1,
    districtId: -1,
    cityId: -1,
    userRoleId: -1,
    status: -1,
    name: '',
    school: '',
    grade: '',
    className: '',
    city: '',
    district: '',
    mail: '',
    identityId: '',
    number: '',
    phone: '',
    address: '',
    nation: '',
    stay: '',
    familyType: '',
    siblingRank: '',
    fatherEdu: '',
    motherEdu: '', // 母亲学历(学生)
    subject: '', // 学科(老师)
    id: -1,
    age: -1,
    isUse: false, // 是否能使用
    sex: '',
    username: '',
    password: '',
    token: '',
    Prompt: false
  },

  // 设置用户属性
  setUserProperty(key, value) {
    this.User[key] = value;
    this.saveUser();
  },

  // 清除用户信息
  clearUser() {
    this.User = {
      token: ''
    };
    this.saveUser();
  },

  // 从本地存储获取用户信息
  getUser() {
    const storedUser = wx.getStorageSync('user');
    if (storedUser) {
      Object.assign(this.User, storedUser);
    }
  },

  // 将用户信息保存到本地存储
  saveUser() {
    wx.setStorageSync('user', this.User);
  }
};

// 导出用户存储
module.exports = {
  userStore
};
